package com.controller;

import com.service.IUserService;
import com.vo.userVo.GiveUserCouponRequestVo;
import com.vo.userVo.GiveUserVipRequestVo;
import com.vo.userVo.UserListRequestVo;
import com.vo.userVo.UserListResponseVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Describe 用户管理控制器
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    HttpServletRequest request;
    @Resource
    IUserService userService;

    /**
     * 获取用户信息列表
     */
    @RequestMapping("/getUserList")
    @ResponseBody
    public List<UserListResponseVo> getUserList(UserListRequestVo vo){
        Object session= request.getSession().getAttribute("user");
        if(session != null) {
            return userService.getUserList(vo);
        }
        return null;
    }

    /**
     * 赠送用户vip
     */
    @PutMapping("/giveUserVip")
    @ResponseBody
    public void giveUserVip(@RequestBody GiveUserVipRequestVo reqVo) {
        Object session = request.getSession().getAttribute("user");
        if (session != null) {
            userService.giveUserVip(reqVo);
        }
    }

    /**
     * 赠送用户优惠券
     */
    @PutMapping("/giveUserCoupon")
    @ResponseBody
    public void giveUserCoupon(@RequestBody GiveUserCouponRequestVo vo) {
        Object session = request.getSession().getAttribute("user");
        if (session != null) {
            userService.giveUserCoupon(vo);
        }
    }
}
